<?php
include_once('common/header.php');
if($AppUI->id > 0) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$strEmail 	= $objRequest->getParam('pfpemail', '');
$strCaptcha	= $objRequest->getParam('pcaptcha', '');
$intError	= 0;
if($strEmail == "" || $strCaptcha == "")
	$intError = 8;
elseif(!Vfriend_Captcha_Image::validate($strCaptcha)) {
	$intError = 2;
}
if($intError == 0) {
	$objVfriendUser = new Vfriend_User();
	$objUser		= $objVfriendUser->getInfoByEmail($strEmail);
	if($objUser) {		
		$intHexUserId 	= $objUser->hex;
		$intExpireTime	= time() + (24*60*60*FORGET_PASSWORD_EXPIRE_TIME);
		// send
		$this->view->intHexUserId	= Vfriend_Function::base64E($intHexUserId);
		$this->view->intExpireTime	= Vfriend_Function::base64E($intExpireTime);
		$this->view->objUser		= $objUser;
		$strSubject		= INDEX_FORGET_PASSWORD_SUB;
		$objView 		= Zend_Registry::get('objView'); 
		$strContent 	= $objView->fetch('email/forget-password.tpl');
		$objMail		= new Vfriend_Mail();
		$intSend		= $objMail->send(EMAIL_NOREPLY, EMAIL_NOREPLY_NAME, $strEmail, $strSubject, $strContent);
		if($intSend)
			Vfriend_Function::redirect(LINK_INDEX_FORGET_PASSWORD . '?userid=' . $intHexUserId);
		else
			$intError = 3;		
	}
	else
		$intError 	= 6;
}
if($intError > 0) {
	$_SESSION['pfpemail']	= $strEmail;
	Vfriend_Function::redirect(LINK_INDEX_FORGET_PASSWORD . '?err=' . $intError);
}

?>